import annotation.Annotation1;
import dto.*;
import org.junit.Test;
import proxy.StarProxy;
import thread.MyCallable;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.*;


public class test {

//    public static final Logger LOGGER = LoggerFactory.getLogger("logback");

    public static void main(String[] args) throws Exception {
//        Runtime r = Runtime.getRuntime();
//        System.out.println(r.availableProcessors());
//        System.out.println(r.totalMemory()/1024.0/1024.0 + "MB");
//        System.out.println(r.freeMemory()/1024.0/1024.0 + "MB");
//        
//        Process p = r.exec("D:\\Program Files (x86)\\Tencent\\QQNT\\QQ.exe");
//        Thread.sleep(5000);
//        p.destroy();
//
//        LocalDate l1 = LocalDate.now();
//        LocalDate l2 = l1.plusDays(10);
//        System.out.println(l2);
//        
//        dto.Student s = () ->{
//            System.out.println(123);
//        };

//        System.out.println("\\.".matches("\\d{3}|[thread.lock.testCyclicBarrier-z]{3}"));
//
//        Pattern compile = Pattern.compile("\\s");
//        
//        throw new TestRuntimeException("asd");

/*        Collection<Integer> thread.lock.testCyclicBarrier = new ArrayList<>();
        ArrayList<Integer> b = new ArrayList<>();
        thread.lock.testCyclicBarrier.add(1);
        thread.lock.testCyclicBarrier.add(2);
        thread.lock.testCyclicBarrier.add(3);
        
        int[] c = new int[b.size()];

//        String[] st = thread.lock.testCyclicBarrier.toArray(new String[thread.lock.testCyclicBarrier.size()]);
//        System.out.println(Arrays.toString(st));
        System.out.println(thread.lock.testCyclicBarrier);*/

//        Set<Double> set = new TreeSet<>(Double::compare);

/*        Set<Double> set = new TreeSet<>(new Comparator<Double>() {
            @Override
            public int compare(Double o1, Double o2) {
                return 0;
            }
        });
        dto.Student s1 = new dto.Student();
        teacher t1 = new teacher();
        dto.people p1 = new dto.people();
        dto.people p2 = new dto.people();
        
        设计模式.单例.danli d1 = 设计模式.单例.danli.create();
        d1.abc((k,v)->{
            
        });
        
        Map<String,Integer> map = new HashMap<>();
        map.put("thread.lock.testCyclicBarrier",map.getOrDefault("thread.lock.testCyclicBarrier",1  ));*/

/*        Map<String, List<String>> listMap = new HashMap<>();
        listMap.put("abc", Arrays.asList("thread.lock.testCyclicBarrier", "b"));
        listMap.put("dsb", Arrays.asList("thread.lock.testCyclicBarrier", "bas"));
        listMap.put("adsb", Arrays.asList("as", "bas"));
        listMap.put("ddsb", Arrays.asList("adf", "bas"));
        listMap.put("edsb", Arrays.asList("aad", "bas"));*/
//        System.out.println(listMap);
//
//        System.out.println(listMap.get("abc"));
//        Map<String, List<String>> stringListMap = Stream.of(listMap).collect(Collectors.toMap(key->key.toString(),val->val.get(key)));
//
//        System.out.println(stringListMap);
//        
        
        /*List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("张三丰");
        list.add("张无忌");
        list.add("浏览");
        list.add("王涛");
        System.out.println(list);
        List<String> s = list.stream().filter(k -> k.startsWith("张") && k.length() == 3).collect(Collectors.toList());
        System.out.println(s);
        
        Arrays.stream(new int[]{1,2,3,4,5}).filter(m->m > 3).forEach(value -> System.out.println(value));
        int[] a2 = Arrays.stream(new int[]{1,2,3,4,5}).filter(m->m > 3).toArray();
        for (int a3 :
                a2) {
            System.out.println(a3);
        }*/


       /* List<Student> students = new ArrayList<>();
        students.add(new Student("abc", 16, 168.5));
        students.add(new Student("abc", 16, 168.5));
        students.add(new Student("thread.lock.testCyclicBarrier", 17, 170.5));
        students.add(new Student("b", 86, 178.5));

        students.stream().distinct().forEach(System.out::println);
        students.stream().distinct().collect(Collectors.toList());


        System.out.println(students);*/

/*        File file = new File("D:\\workfile\\学习\\test\\thread.lock.testCyclicBarrier");
        File file1 = new File("D:\\workfile\\学习\\test\\thread.lock.testCyclicBarrier\\b\\d\\thread.lock.testCyclicBarrier\\asdf\\zxc\\thread.lock.testCyclicBarrier\\we\\asdf\\asdf\\zxv");
        file1.mkdirs();
        DeleteDirectory deleteDirectory = new DeleteDirectory();
        System.out.println(deleteDirectory.delete(file));*/
        
/*        String s = "lasd1;";
        byte[] bytes = s.getBytes();
        System.out.println(Arrays.toString(bytes));
        String s1 = new String(bytes);
        System.out.println(s1);*/

/*        InputStream inputStream = new FileInputStream("D:\\workfile\\学习\\新建 文本文档.txt");
        LocalDateTime start = LocalDateTime.now();
        System.out.println((char) inputStream.read());
        System.out.println(start);
        int s;
        while ((s = inputStream.read()) != -1){
            System.out.print(s);
        }
        LocalDateTime end = LocalDateTime.now();
        System.out.println(end);
        System.out.println(Duration.between(start, end));
        inputStream.close();*/


//        InputStream inputStream = new FileInputStream("D:\\workfile\\学习\\新建 文本文档.txt");
//        LocalDateTime start = LocalDateTime.now();
////        System.out.println((char) inputStream.read());
//        System.out.println(start);

//        File file = new File("D:\\workfile\\学习\\新建 文本文档.txt");
//        byte[] bytes = new byte[(int) file.length()];
//        if (inputStream.read(bytes) != -1) {
//            System.out.print(new String(bytes));
//        }

/*        byte[] bytes = inputStream.readAllBytes();
        System.out.println(new String(bytes));
        System.out.println();
        LocalDateTime end = LocalDateTime.now();
        System.out.println(end);
        System.out.println(Duration.between(start, end));
        inputStream.close();


        OutputStream outputStream = new FileOutputStream("D:\\workfile\\学习\\新建 文本文档.txt",true);
        outputStream.write('1');
        outputStream.close();*/
        
/*        try(
                InputStream inputStream = new FileInputStream("D:\\workfile\\学习\\新建文件夹\\thread.lock.testCyclicBarrier\\QQ截图20220927130453.png");
                OutputStream outputStream = new FileOutputStream("D:\\workfile\\学习\\新建文件夹\\b\\copy.png");
                ) {
            byte[] bytes = new byte[1024 * 1024];
            int len;
            while ((len = inputStream.read(bytes)) != -1) {
                outputStream.write(bytes, 0, len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }*/

/*        try(
                Reader reader = new FileReader("D:\\workfile\\学习\\新建文件夹\\thread.lock.testCyclicBarrier\\新建 文本文档.txt");
                BufferedReader bufferedReader = new BufferedReader(reader);
                Writer writer = new FileWriter("D:\\workfile\\学习\\新建文件夹\\b\\copy.txt");
                BufferedWriter bufferedWriter = new BufferedWriter(writer);
        ) {
            char[] chars = new char[1024 * 1024];
            int len;
            while ((len = reader.read(chars)) != -1) {
                writer.write(chars, 0, len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }*/

/*        List<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(4);
        list.add(3);
        list.add(2);
        list.sort((o1, o2) -> {
            return o1 - o2;
        });

        System.out.println(list);
        MyLinkedList<Integer>linkedList = new MyLinkedList();
        linkedList.sort((o1, o2) -> o1 - o2);
        
        BufferedWriter writer =new BufferedWriter( new OutputStreamWriter(new FileOutputStream(""),"GBK"));*/

/*        try (
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("b.txt"));
                
                ){
//            Student student = new Student("ylh",18,123.3);
//            oos.writeObject(student);
//            oos.writeObject(student);
            List<Integer> list = new ArrayList<>();
            list.add(1);
            list.add(1);
            list.add(1);
            oos.writeObject(list);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        try (
                
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream("b.txt") );
                ){
//            Student student1 = (Student) ois.readObject();
//            Student student2 = (Student) ois.readObject();
//            
//            System.out.println(student1);
//            System.out.println(student2);
            List<Integer> list = (List<Integer>) ois.readObject();
            System.out.println(list);
        } catch (Exception e) {
            e.printStackTrace();
        }*/
        
/*        Properties properties = new Properties();
        properties.setProperty("qe","we");
        properties.setProperty("qe1","we2");
        properties.load(new FileReader("asd.properties"));
        if (properties.contains("qe")) {
            properties.setProperty("qe","qwel");
            
        }
        properties.store(new FileWriter("asd.properties"),"success");*/

/*        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read("src/testdData/asd.xml");
        Element rootElement = document.getRootElement();
        System.out.println(rootElement.getName());

        
        List<Element> elements = rootElement.elements();
        List<Element> elements2 = rootElement.elements("user");
        for (Element element : elements2) {
            System.out.println(element.getName());
            System.out.println(element.getText());
        }*/
/*        LOGGER.info("hhh");
        LOGGER.debug("hhh");
        LOGGER.debug("------>debug log");
        LOGGER.info("------>info log");
        LOGGER.error("------>error log");
        LOGGER.trace("asdf");
        LOGGER.trace("asdf");*/

//        Thread t1 = new MyThread();
//        t1.start();
//        Thread.sleep(1000);
//        Thread t2 = new MyThread();
//        t2.start();
//        Thread t3 = new MyThread();
//        t3.start();
//        Thread t4 = new MyThread();
//        t4.start();


//        Runnable runnable = new MyRunnable();
//        new Thread(runnable).start();
//        Runnable runnable2 = new MyRunnable();
//        new Thread(runnable2).start();
//        Runnable runnable3 = new MyRunnable();
//        new Thread(runnable3).start();

/*        new Thread(new Runnable() {
            @Override
            public void run() {

            }
        });

        new Thread(()->{

        }).start();*/


/*        MyCallable myCallable = new MyCallable(10);
        FutureTask<String> stringFutureTask = new FutureTask<>(myCallable);
        new Thread(stringFutureTask).start();

        
        MyCallable myCallable2 = new MyCallable(20);
        FutureTask<String> stringFutureTask2 = new FutureTask<>(myCallable2);
        new Thread(stringFutureTask2).start();
        
        System.out.println(stringFutureTask.get());
        System.out.println(stringFutureTask2.get());

        for (int i = 0; i < 10; i++) {
            System.out.println("主线程 " + i);
        }*/


/*        Account acc = new Account("123",1000);
        Account acc2 = new Account("324",1000);
        Thread thread1 = new Thread(new MyRunnable(acc, "小红"));
        Thread thread2 = new Thread(new MyRunnable(acc, "小明"));

        MyThread thread3 = new MyThread(acc, "小红");
        MyThread thread4 = new MyThread(acc, "小明");

        MyThread thread5 = new MyThread(acc2, "小明2");
        MyThread thread6 = new MyThread(acc2, "小红2");

        ExecutorService poolExecutor = new ThreadPoolExecutor(3, 5, 2000, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(4), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        
        poolExecutor.execute(thread1);
        poolExecutor.execute(thread2);
        poolExecutor.execute(thread4);
        poolExecutor.execute(thread5);
        poolExecutor.execute(thread3);
        poolExecutor.execute(thread6);
        
        poolExecutor.shutdown();*/
        
        
        /*ExecutorService pool = new ThreadPoolExecutor(3, 5, 2000, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(4), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        Executors.newFixedThreadPool(3);
        
        
        Future<String> submit = pool.submit(new MyCallable(10, "thread.lock.testCyclicBarrier"));
        Future<String> submit2 = pool.submit(new MyCallable(20,"b"));
        Future<String> submit3 = pool.submit(new MyCallable(15,"b"));
        Future<String> submit4 = pool.submit(new MyCallable(14,"b"));
        System.out.println(submit.get());
        System.out.println(submit2.get());
        System.out.println(submit3.get());
        System.out.println(submit4.get());


        pool.shutdown();*/

/*        DatagramSocket socket = new DatagramSocket();
        
        byte[] bytes = "为附加搜地sdio".getBytes();
        DatagramPacket packet = new DatagramPacket(bytes,bytes.length, InetAddress.getLocalHost(),
                6789);
        
        socket.send(packet);
        
        socket.close();*/

/*        DatagramSocket socket = new DatagramSocket();
        Scanner scanner = new Scanner(System.in);
        while (true) {
            String s = scanner.nextLine();
            if ("exit".equals(s)){
                socket.close();
                break;
            }
            byte[] bytes = s.getBytes();
            
            DatagramPacket packet = new DatagramPacket(bytes,bytes.length, InetAddress.getLocalHost(),
                    6789);

            socket.send(packet);
        }*/


        
/*        Socket socket = new Socket("127.0.0.1", 6789);
        OutputStream outputStream = socket.getOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
        Scanner scanner = new Scanner(System.in);

        while (true) {
            String s = scanner.nextLine();
            if ("exit".equals(s)) {
                dataOutputStream.close();
                socket.close();
                break;
            }
            dataOutputStream.writeUTF(s);
        }*/


        Class<Student> studentClass = Student.class;
        System.out.println(studentClass.getName());
        System.out.println(studentClass.getSimpleName());

//        Class<?> aClass = Class.forName("dto.Student");
//        System.out.println(studentClass == aClass);
//
//        Student student = new Student();
//        Class aClass1 = student.getClass();
//        System.out.println(aClass1 == studentClass);

//        Constructor<?>[] constructors = studentClass.getConstructors();
        Constructor<?>[] declaredConstructors = studentClass.getDeclaredConstructors();
        for (Constructor<?> constructor : declaredConstructors) {
            System.out.println(constructor.getName() + "---->" + constructor.getParameterCount());
        }
    }
    
    @Test
    public void testGetStudentConstructor() throws Exception {
        Class<Student> studentClass = Student.class;
        Constructor constructor1 = studentClass.getDeclaredConstructor();
        System.out.println(constructor1.getName() + "---->" + constructor1.getParameterCount());
        constructor1.setAccessible(true);
        Student student = (Student) constructor1.newInstance();
        System.out.println(student);

        Constructor constructor2 = studentClass.getDeclaredConstructor(String.class,int.class,double.class);
        System.out.println(constructor2.getName() + "---->" + constructor2.getParameterCount());
        Student student2 = (Student) constructor2.newInstance("ylh",22,188.4);
        System.out.println(student2);
        
    }

    @Test
    public void testGetStudentField() throws Exception {
        Class studentClass = Student.class;
        Field[] declaredFields = studentClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField.getName() +"  "+ declaredField.getType());
        }

        Field name = studentClass.getDeclaredField("name");
        System.out.println(name.getName() +"  " + name.getType());

        Student student = new Student();
        name.setAccessible(true);
        name.set(student,"ylh");
        System.out.println(student);

        System.out.println(name.get(student));
    }


    @Test
    public void testGetStudentMethod() throws Exception {
        Class studentClass = Student.class;
        Method[] declaredMethods = studentClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod.getName() + "  " 
            + declaredMethod.getParameterCount() + "  "
            + declaredMethod.getReturnType());
        }

        Method setName = studentClass.getDeclaredMethod("setName", String.class);
        System.out.println(setName.getName() + "  "
                + setName.getParameterCount() + "  "
                + setName.getReturnType());


        Student student = new Student();
        setName.setAccessible(true);
        System.out.println(setName.invoke(student, "ylh"));
        System.out.println(student.getName());
    }
    
    @Test
    public void testAnnotation1() throws Exception{
        Class a = Annotation1.class;
        Annotation[] declaredAnnotations = a.getDeclaredAnnotations();
        for (Annotation declaredAnnotation : declaredAnnotations) {
            System.out.println(declaredAnnotation);
        }
    }
    
    @Test
    public void testBigStarProxy(){
        BigStar ycy = new BigStar("杨超越");
        Star starProxy = StarProxy.createStarProxy(ycy);
        
        String s = starProxy.sing("有点甜");
        System.out.println(s);
        
        starProxy.dance();
    }
    
    @Test
    public void testZileiduotai(){
        Person a = new boy();
        Person b = new girl();
        Map<Integer,Integer> map = new ConcurrentHashMap<>();
        a.drink();
        b.drink();
        
    }

    @Test
    public void testCallable() throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable(10);
        FutureTask futureTask = new FutureTask(myCallable);
        
        new Thread(futureTask,"A").start();
        new Thread(futureTask,"B").start();

        String i = (String) futureTask.get();
        String j = (String) futureTask.get();
        System.out.println(i);
        System.out.println(j);
    }
    
    @Test
    public void testCyclicBarrier(){
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7,()->{
            System.out.println("召唤神龙");
        });

        for (int i = 1; i <= 7; i++) {
            final int temp = i;
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + " " + temp);

                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
            }).start();
        }
    }
    
    
    
}

/*
interface dto.Student{
    void study();
    
//    void teach();
}*/
